<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>分组</title>
</head>
<body>
  <script>
    let array = [
      [1, 2, 3],
      [1, 3, 5],
      [1, 5, 9]
    ]
    let fn = function (list) {
      return String(list[0]);
    }

    Array.prototype.groupBy = function(fn) {
      let res = {}
      for(let item of this){
        let key = fn(item); // key 是3个1
        // 判断 key 这个属性是否不在 res 对象中
        if(!res.hasOwnProperty(key)) res[key] = [];
        res[key].push(item)
      }
      return res
    }
    console.log(array.groupBy(fn))
  </script>
</body>
</html>